package com.cudex.negocio.beans;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import com.cudex.negocio.enums.TipoFactura;

/**
 * @author Nicolas Bordenave
 * @date 22/11/2011
 * @version 1.0
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "buscarFacturas", query = "SELECT f FROM Facturas f"),
		@NamedQuery(name = "buscarFactura", query = "SELECT f FROM Facturas f WHERE f =:Fac"), //})
		@NamedQuery(name = "buscarFacturaCliente", query = "SELECT f FROM Facturas f WHERE f.cli =:Cli") })
public class Facturas implements Serializable {

	private static final long serialVersionUID = 4151841115567934280L;

	@Column(name = "Serie", nullable = false, unique = true, insertable = false, updatable = false)
	private String serie;

	@Column(name = "Numero", nullable = false, unique = true, insertable = false, updatable = false)
	private int numero;

	@Column(name = "fEmision", nullable = false)
	private Date fEmision;

	@Column(name = "fVencimiento", nullable = false)
	private Date fVencimiento;

	@Column(name = "moneda", nullable = false)
	private int moneda;

	@Column(name = "subTotal", nullable = false)
	private double subTotal;

	@Column(name = "iva", nullable = false)
	private double iva;

	@Column(name = "total", nullable = false)
	private double total;

	@Column(name = "ordenTrabajo")
	private int ordenTrabajo;

	@ManyToOne
	@JoinColumn(name = "rut")
	private Clientes cli;

	@Enumerated(EnumType.STRING)
	private TipoFactura tipoFactura;

	@EmbeddedId
	private FacturaPK fKey;

	public String getSerie() {
		return serie;
	}

	public void setSerie(String serie) {
		this.serie = serie;
	}

	public int getNumero() {
		return numero;
	}

	public void setNumero(int numero) {
		this.numero = numero;
	}

	public Date getfEmision() {
		return fEmision;
	}

	public void setfEmision(Date fEmision) {
		this.fEmision = fEmision;
	}

	public Date getfVencimiento() {
		return fVencimiento;
	}

	public void setfVencimiento(Date fVencimiento) {
		this.fVencimiento = fVencimiento;
	}

	public int getMoneda() {
		return moneda;
	}

	public void setMoneda(int moneda) {
		this.moneda = moneda;
	}

	public double getSubTotal() {
		return subTotal;
	}

	public void setSubTotal(double subTotal) {
		this.subTotal = subTotal;
	}

	public double getIva() {
		return iva;
	}

	public void setIva(double iva) {
		this.iva = iva;
	}

	public double getTotal() {
		return total;
	}

	public void setTotal(double total) {
		this.total = total;
	}

	public int getOrdenTrabajo() {
		return ordenTrabajo;
	}

	public void setOrdenTrabajo(int ordenTrabajo) {
		this.ordenTrabajo = ordenTrabajo;
	}

	public Clientes getCliente() {
		return cli;
	}

	public void setCliente(Clientes cliente) {
		this.cli = cliente;
	}

	public TipoFactura getTipoFactura() {
		return tipoFactura;
	}

	public void setTipoFactura(TipoFactura tipoFactura) {
		this.tipoFactura = tipoFactura;
	}

	public FacturaPK getfKey() {
		return fKey;
	}

	public void setfKey(FacturaPK fKey) {
		this.fKey = fKey;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((fEmision == null) ? 0 : fEmision.hashCode());
		result = prime * result + numero;
		result = prime * result + ((serie == null) ? 0 : serie.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Facturas other = (Facturas) obj;
		if (fEmision == null) {
			if (other.fEmision != null)
				return false;
		} else if (!fEmision.equals(other.fEmision))
			return false;
		if (numero != other.numero)
			return false;
		if (serie == null) {
			if (other.serie != null)
				return false;
		} else if (!serie.equals(other.serie))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Factura : " + getSerie() + getNumero() + " Total: "
				+ getTotal();
	}
}
